<template>
  <div>
    <el-table :data="tableData" style="width: 100% background:#545c64" border>
      <el-table-column type="index" label="序号" width="60" align="center" />

      <el-table-column label="商品ID">
        <template slot-scope="scope">
          <i class="el-icon-edit-outline"></i>
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品名称">
        <template slot-scope="scope">
          <i class="el-icon-goods"></i>
          <span style="margin-left: 10px">{{ scope.row.spuname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺ID">
        <template slot-scope="scope">
          <i class="el-icon-goods"></i>
          <span style="margin-left: 10px">{{ scope.row.shopId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="￥商品价格">
        <template slot-scope="scope">
          <i class="el-icon-shopping-cart-1"></i>
          <span style="margin-left: 10px">{{ scope.row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品品牌">
        <template slot-scope="scope">
          <i class="el-icon-shopping-cart-1"></i>
          <span style="margin-left: 10px">{{ scope.row.brand }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品库存">
        <template slot-scope="scope">
          <i class="el-icon-coin"></i>
          <span style="margin-left: 10px">{{ scope.row.num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品简介">
        <template slot-scope="scope">
          <i class="el-icon-receiving"></i>
          <span style="margin-left: 10px">{{ scope.row.intro }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.createdTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="open(scope.$index, scope.row)"
            >取消上架</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <span>您确定要取消上架吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="deleteSpu">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getSpuList, deleteSpu } from "../api/goods";
export default {
  inject: ["reload"],
  data() {
    return {
      tableData: [],
      dialogVisible: false,
    };
  },
  mounted() {
    getSpuList()
      .then((data) => {
        let res = data.data;
        this.tableData = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  methods: {
    open(index, row) {
      this.dialogVisible = true;
      this.tableData.id = row.id;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    deleteSpu() {
      deleteSpu(this.tableData.id)
        .then((data) => {
          console.log(data);
          this.dialogVisible = false;
          this.$message.success("取消上架成功！")
          this.reload();
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
</style>